import Http from "./http";

/* 获取最新新闻 */
export const queryNewsLatest = () => {
  return Http.get("/api/news_latest");
};

/* 获取以往新闻 */
export const queryNewsBefore = (time) => {
  return Http.get("/api/news_before", {
    params: {
      time,
    },
  });
};

/* 获取新闻详细信息 */
export const getInfo = (id) => {
  return Http.get("/api/news_info", {
    params: {
      id,
    },
  });
};

/* 获取新闻点赞信息 */
export const queryStoryExtra = (id) => {
  return Http.get("/api/story_extra", {
    params: {
      id,
    },
  });
};

/* 用户登录 */
export const login = (phone, code) => {
  return Http.post("/api/login", {
    phone,
    code,
  });
};

/* 获取手机验证码 */
export const getPhoneCode = (phone) => {
  return Http.post("/api/phone_code", {
    phone,
  });
};

/* 获取登录者信息 */
export const getUserInfo = () => {
  return Http.get("/api/user_info");
};

/* 上传图片   格式:multipart/form-data */
export const updateAvatar = (file) => {
  return Http.post("/api/upload", {
    params: {
      file
    }
  });
};

/* 修改用户信息 */
export const userUpdate = (username, pic) => {
  let params = {};
  username ? params.username = username : null;
  pic ? params.pic = pic : null;
  return Http.post("/api/user_update", params);
};

/* 收藏新闻 */
export const setStore = (newsId) => {
  return Http.post("/api/store", {
    newsId
  });
};

/* 移除收藏 */
export const storeRemove = (id) => {
  return Http.get("/api/store_remove", {
    params: {
      id
    }
  });
};

/* 获取用户收藏列表 */
export const queryUserStoreList = () => {
  return Http.get("/api/store_list");
};
